﻿using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ServiceModel;

using Contract.ServiceContracts;

using Service.ServiceInstances;



namespace SelfHost.TcpPortSharingConsole
{

    class Program
    {

        static void Main(string[] args)
        {

            //1.tcp port share service is running.



            //2.create 2 diff contacts in 2 services host by same port



            NetTcpBinding bind = new NetTcpBinding();

            bind.PortSharingEnabled = true;



            ServiceHost host1 = new ServiceHost(typeof(MathClass));

            host1.AddServiceEndpoint(typeof(IMathServices), bind, "net.tcp://localhost:800/Service1");





            ServiceHost host2 = new ServiceHost(typeof(TestDataClass));

            host2.AddServiceEndpoint(typeof(ITestData), bind, "net.tcp://localhost:800/Service2");



            try
            {

                host1.Open();

                host2.Open();



                Console.ReadLine();

            }

            catch (Exception exp)
            {

                throw exp;

            }

            finally
            {

                host1.Close();

                host2.Close();

            }





        }

    }

}

